#include"Mylineitem.h"

Mylineitem::Mylineitem(MyRectItem* a,MyRectItem* b,int x1,int y1,int x2,int y2):QGraphicsLineItem(x1,y1,x2,y2)
{
    from=a;
    to=b;
    connect(from, &MyRectItem::positionChanged, this, &Mylineitem::updateLinePosition);
    connect(to, &MyRectItem::positionChanged, this, &Mylineitem::updateLinePosition);
}
void Mylineitem::updateLinePosition()
{
    QPointF startPoint = from->mapToScene(from->boundingRect().center());
    QPointF endPoint=to->mapToScene(to->boundingRect().center());
    setLine(QLineF(startPoint, endPoint));
    // 更新线条的位置，确保线条在矩形的上层
    setZValue(-1000);
}
